package io.github.weiranyi.service.impl;

import io.github.weiranyi.dao.UserDao;
import io.github.weiranyi.dao.impl.UserDaoImpl;
import io.github.weiranyi.service.UserService;
import io.github.weiranyi.utils.BeanFactory;

public class UserServiceImpl implements UserService {

    public void save() {
        // 1.编译期依赖问题： userDao = new UserDaoImpl();new一个对象也会增大服务器压力
        try {
            // 2.反射：存在硬编码问题
            // UserDao userDao = Class.forName("io.github.weiranyi.dao.impl.UserDaoImpl").newInstance();
            UserDao userDao = (UserDao) BeanFactory.getBean("userDao");
            userDao.save();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
